/*******************************************************************************
* @copyright: Shenzhen Hangshun Chip Technology R&D Co., Ltd
* @filename:  hk32g003_it.c
* @brief:     Interrupt Service Routines
* @author:    AE Team
* @version:   V1.0.0/2025-03-10
*             1.Initial version
* @log:
*******************************************************************************/


/* Includes ------------------------------------------------------------------*/
#include "hk32g003_it.h"


/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
extern __IO uint16_t ADC_Channel4_ConvertedValue;
extern __IO uint16_t ADC_Channel_Vrefint_ConvertedValue;
extern uint8_t ADC_SEQ_FLAG;

/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/******************************************************************************/
/*            Cortex-M0 Processor Exceptions Handlers                         */
/******************************************************************************/

/**
  * @brief  This function handles NMI exception.
  * @param  None
  * @retval None
  */
void NMI_Handler(void)
{
}

/**
  * @brief  This function handles Hard Fault exception.
  * @param  None
  * @retval None
  */
void HardFault_Handler(void)
{
  /* Go to infinite loop when Hard Fault exception occurs */
  while (1)
  {
  }
}

/**
  * @brief  This function handles SVCall exception.
  * @param  None
  * @retval None
  */
void SVC_Handler(void)
{
}

/**
  * @brief  This function handles PendSVC exception.
  * @param  None
  * @retval None
  */
void PendSV_Handler(void)
{
}

/**
  * @brief  This function handles SysTick Handler.
  * @param  None
  * @retval None
  */
void SysTick_Handler(void)
{
}

/******************************************************************************/
/*             HK32G003 Peripherals Interrupt Handlers                   */
/*  Add here the Interrupt Handler for the used peripheral(s) (PPP), for the  */
/*  available peripheral interrupt handler's name please refer to the startup */
/*  file (KEIL_startup_hk32g003.s).                                      */
/******************************************************************************/

/**
  * @brief  This function handles ADC1 interrupt request.
  * @param  None
  * @retval None
  */
void ADC1_IRQHandler(void)
{
  /* ADC convert counter variable */
  static uint8_t count = 0;
  
	/* ADC EOC interrupt */
  if (ADC_GetITStatus(ADC,ADC_IT_EOC)==SET) 
	{
    ADC_ClearITPendingBit(ADC,ADC_IT_EOC);

    if( count == 0 )
    {
      ADC_Channel4_ConvertedValue = ADC_GetConversionValue(ADC);
    }
    
    if( count == 1 )
    {
      ADC_Channel_Vrefint_ConvertedValue = ADC_GetConversionValue(ADC);
    }
		
    count ++;
	}
  
	/* ADC EOSEQ interrupt */
  if (ADC_GetITStatus(ADC,ADC_IT_EOSEQ)==SET) 
	{
    ADC_ClearITPendingBit(ADC,ADC_IT_EOSEQ);
    ADC_SEQ_FLAG = SET;
		count = 0;
	}
}

/**
  * @brief  This function handles PPP interrupt request.
  * @param  None
  * @retval None
  */
/*void PPP_IRQHandler(void)
{
}*/


